﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoVanHocTapData.Entities;
using CoVanHocTapData.Interface;

namespace CoVanHocTapData.Concretes
{
    public class ChiTietKhoiCTDTRepository : IChiTietKhoiCTDTRepository
    {
        DangKyPhuEntities entities;

        #region repos
        IRangBuocMonRepository rangBuocMonRepos = new RangBuocMonRepository();
        #endregion

        public ChiTietKhoiCTDTRepository()
        {
            entities = new DangKyPhuEntities();
        }

        #region IChiTietKhoiCTDTRepository Members

        public List<MonHocTheoHocKy> layChiTietKhoiCTDT(string nganhID, int khoiCTDTID, string hocKy)
        {

            var ctKhoiCTDT = (from m in entities.ChiTietKhoiCTDTs
                              join n in entities.MonHocs
                              on m.MonHocID equals n.MonHocID
                              join l in entities.KhoiChuongTrinhDaoTaos
                              on m.KhoiChuongTrinhDaoTaoID equals l.ID
                              where m.KhoiChuongTrinhDaoTaoID == khoiCTDTID
                              select new MonHocTheoHocKy
                              {
                                  DVHT = n.SoDVHocTap.Value,
                                  HocKy = hocKy,
                                  LaMonTuChon = true,
                                  MonHocID = n.MonHocID,
                                  TenKhoiMonTuChon = l.TenKhoiMonHoc,
                                  TenMonHoc = n.TenMonHoc,
                                  CungNhom = m.LaCungNhom

                              }
                        );
            string strSongHanh, strTienQuyet, strTruoc;
            List<MonHocTheoHocKy> resultList = new List<MonHocTheoHocKy>();
            foreach (var ctItem in ctKhoiCTDT)
            {
                if (rangBuocMonRepos.LayMonRangBuoc(ctItem.MonHocID, nganhID, out strSongHanh, out strTienQuyet, out strTruoc))
                {
                    ctItem.MonHocSongHanh = strSongHanh;
                    ctItem.MonHocTienQuyet = strTienQuyet;
                    ctItem.MonHocTruoc = strTruoc;
                    resultList.Add(ctItem);
                }
            }
            return resultList;
        }

        #endregion
    }
}
